define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/order/index' + location.search,
                    add_url: 'shop/order/add',
                    edit_url: 'shop/order/edit',
                    del_url: 'shop/order/del',
                    multi_url: 'shop/order/multi',
                    import_url: 'shop/order/import',
                    table: 'shop_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'order_no', title: __('Order_no'), operate: false},
                        {field: 'shopproduct.name', title: __('Shopproduct.name'), operate: false},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate: false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'shopproduct.integral', title: __('Shopproduct.integral'), operate: false},
                        {field: 'shopproduct.shopstore.name', title: __('Shopproduct.shopstore.name'), operate: false},
                        {field: 'code', title: __('Code'), operate: "LIKE"},
                        {field: 'status', title: __('Status'), operate: false, searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'),
                            formatter: function(value, row){
                                if(row.status==0){
                                    value = '<a style="cursor: pointer;" href="javascript:;" data-toggle="tooltip" title="" class="btn-change " data-index="0" data-id="'+row.id+'" data-params="status=1" data-original-title="点击兑换">兑换</a>';
                                }
                                return value;
                            }
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});